home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 04 / v_gotorc.c < prev    next >
C/C++ Source or Header  |  1991-05-03  |  983b  |  32 lines

  1. /*    v_gotorc.c- Move Cursor Within Viewport */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <tools/viewport.h>
  7.  
  8. int v_gotorc( viewport *v, unsigned row, unsigned col )
  9. {
  10.     /* Move the cursor to the indicated viewport-relative row
  11.      * and column. The cursor is not allowed to go past the edge
  12.      * of the viewport. Nonetheless, it will go as far as possible
  13.      * in the required direction. Return true if the cursor ended
  14.      * up where specified, false if it didn't because it bumped
  15.      * up against the side of the viewport.
  16.      */
  17.  
  18.     if( v->magic != VMAGIC )
  19.         return 0;
  20.  
  21.     if( v->inactive )
  22.         v_open( v );
  23.  
  24.     v->cur_row = min( row, v->nrows - 1 ); /* truncate to fit in window */
  25.     v->cur_col = min( col, v->ncols - 1 );
  26.  
  27.     window( v->col+1, v->row+1, v->col+v->ncols, v->row+v->nrows );
  28.     gotoxy( v->cur_col + 1, v->cur_row + 1 );
  29.  
  30.     return (v->cur_row == row  &&  v->cur_col == col);
  31. }
  32.